package com.cci.kangdao.controller;

import com.cci.kangdao.aop.UserThreadLocal;
import com.cci.kangdao.dao.model.UserT;
import com.cci.kangdao.service.FeedbackService;
import com.cci.kangdao.utilTool.Date_Util;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 用户反馈
 *
 * @author fengshuai
 *
 */
@Controller
public class UserFeedbackController {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Resource
	private FeedbackService feedbackService;

	/**
	 * App意见反馈接口
	 */
	@RequestMapping("/submitFeedback.aspx")
	public ModelAndView submitFeedback(HttpServletRequest request, HttpServletResponse response) {

		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.submitFeedback(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	/**
	 * App用户获取app版本接口
	 */
	@RequestMapping("/getAppVersion.aspx")
	public ModelAndView getAppVersion(HttpServletRequest request, HttpServletResponse response) {

		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.getAppVersion(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	/*
	 * @description: app升级用户忽略记录表
	 * @param:
	 * @return: void
	 * @author: yinguili
	 * @date: 2022/9/8 14:06
	 */
	@RequestMapping("/upgradeIgnore.aspx")
	public ModelAndView upgradeIgnore(HttpServletRequest request, HttpServletResponse response) {

		try {
			UserT userT = UserThreadLocal.get();
			String nowTime = Date_Util.getNowTime();
			boolean success = feedbackService.addUserIgnoreUpgradeRecord(userT, nowTime);
			if (success) {
				/**
				 * 注释log
				 * 20230808
				 * sxt 处理Privacy Violation
				 */
				//log.info("用户" + userT.getUserName() + "在" + nowTime + "点击暂不升级");
				ParameterTool.writeSuccessResponse(response);
			} else {
				String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
				ParameterTool.writeResponse(response, msg);
			}
			return null;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
